<template>
  <el-dialog :visible.sync="visible" width="335px" custom-class="payment-qr-dialog" :show-close="false"
    :close-on-click-modal="false" :close-on-press-escape="false">
    <div class="qr-content">
      <div class="qr-code">
        <img :src="qrCodeUrl" alt="支付二维码">
      </div>
      <div class="amount">¥{{ amount.toFixed(2) }}</div>
      <div class="tip">使用微信扫码付款，付款后点击已付款</div>
      <div class="buttons">
        <el-button @click="handleCancel">取消</el-button>
        <el-button type="primary" @click="handlePaid">我已付款</el-button>
      </div>
    </div>
  </el-dialog>
</template>

<script>
export default {
  name: 'PaymentQRDialog',
  props: {
    visible: {
      type: Boolean,
      default: false
    },
    amount: {
      type: Number,
      required: true
    }
  },
  data () {
    return {
      // 这里使用示例二维码图片，实际项目中应该从后端获取支付二维码
      qrCodeUrl: 'https://api.qrserver.com/v1/create-qr-code/?size=200x200&data=example'
    }
  },
  methods: {
    handleCancel () {
      this.$emit('update:visible', false)
      this.$emit('cancel')
    },
    handlePaid () {
      this.$emit('update:visible', false)
      this.$emit('paid')
    }
  }
}
</script>

<style lang="scss" scoped>
.payment-qr-dialog {
  ::v-deep .el-dialog__header {
    display: none;
  }

  ::v-deep .el-dialog__body {
    padding: 30px;
  }

  .qr-content {
    text-align: center;
  }

  .qr-code {
    width: 200px;
    height: 200px;
    margin: 0 auto 20px;

    img {
      width: 100%;
      height: 100%;
    }
  }

  .amount {
    font-size: 24px;
    font-weight: bold;
    margin-bottom: 12px;
  }

  .tip {
    color: #666;
    font-size: 14px;
    margin-bottom: 24px;
  }

  .buttons {
    display: flex;
    gap: 12px;

    .el-button {
      flex: 1;
    }
  }
}
</style>